package client.network;

import java.awt.Point;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;

import packages.Packages;

public class ClientOutgoingPosition extends Thread {

	private DrawMailBox drawMailBox;
	private OutputStream ostream;

	public ClientOutgoingPosition(OutputStream ostream, DrawMailBox drawMailBox) {
		this.drawMailBox = drawMailBox;
		this.ostream = ostream;
	}

	@Override
	public void run() {
		while (!interrupted()) {
			try {
				ArrayList<Point> points = drawMailBox.getOutgoingPoints();
				String pack = makePositionMessage(points);
				ostream.write(Packages.PACKAGE_POSITIONS);
				ostream.write(pack.getBytes());
				
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	public String makePositionMessage(ArrayList<Point> p){
		String toReturn = " ";
		for(Point point: p){
			toReturn += (point.x + "," + point.y + " "); 
		}
		toReturn += "\n";
		return toReturn;
	}
	

}
